package com.example.springbootsfzy.service.sunkaixuan;


import com.example.springbootsfzy.domain.PrivateMessages;
import com.example.springbootsfzy.mapper.PrivateMessagesMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PrivateMessageService {
    @Autowired
    private PrivateMessagesMapper privateMessagesMapper;

    //根据memberId查看全部
    public List<PrivateMessages> getPrivateMessages(int id) {
        return privateMessagesMapper.getPrivateMessages(id);
    }

    //根据messageId查
    public PrivateMessages getPrivateMessageById(int id){
        return privateMessagesMapper.selectByPrimaryKey(id);
    }

    //通过consultant_id查
    public List<PrivateMessages> selectByconsultantid(int consultantid){
        return privateMessagesMapper.selectByconsultantid(consultantid);
    }


    //添加
    public int addPrivateMessage(PrivateMessages privateMessages) {
        return privateMessagesMapper.insertSelective(privateMessages);
    }

    //删除
    public int deletePrivateMessage(int id) {
        return privateMessagesMapper.deleteByPrimaryKey(id);
    }

    //修改
    public int updatePrivateMessage(PrivateMessages privateMessages) {
        return privateMessagesMapper.updateByPrimaryKeySelective(privateMessages);
    }

    /**
     * 分页查询私信展示在咨询师页面
     */
    public PageInfo<PrivateMessages> getPrivateMessagesByConsultantId(int pageNum, int pageSize ,int consultantId) {
        PageHelper.startPage(pageNum, pageSize);
        Page<PrivateMessages> page = privateMessagesMapper.getPrivateMessagesByConsultantId(consultantId);
        return new PageInfo<>(page);
    }



}
